<?php

namespace SGBD;

class AbstractController
{
    public function __construct(\Slim\Slim $app, Persistance\iDB $db)
    {
        $this->app = $app;
        $this->db = $db;
    }

    protected function getSaisonParam()
    {
        $saison = $this->app->request()->get('saison');
        if (!empty($saison)) {
            return explode('-', $saison);
        } else {
            return FALSE;
        }
    }

    protected function redirect($route, $args = array())
    {
        $url = $this->app->urlFor($route, $args);
        $this->app->redirect($url);
    }

    protected function link($route, $args, $label, $klass = '')
    {
        $url = $this->app->urlFor($route, $args);
        return '<a class="' . $klass . '"href="' . $url . '">' . $label . '</a>';
    }

    protected function equipesToOptions(array $equipes) {
        foreach ($equipes as &$e) {
            $e['_Nom_Abs'] = $e['Nom_Club'] . ' > ' . $e['Nom_Categorie']
                . ' > ' . $e['Nom_Equipe'];
        }
        return $equipes;
    }

    protected function linkRencontres(array $matches) {
        foreach ($matches as &$m) {
            $m['_href'] = $this->app->urlFor(
                'rencontre_view', array('Numero_Rencontre' => $m['Numero_Rencontre'])
            );
        }
        return $matches;
    }

}